#include "GLWindow.h"
#include <QOpenGLFunctions>
#include <QDebug>


#define MY_GL_FUNC  context()->functions()


void GLWindow::initializeGL()
{
    MY_GL_FUNC->initializeOpenGLFunctions();
    MY_GL_FUNC->glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
    printContextInformation();
}

void GLWindow::paintGL()
{
    MY_GL_FUNC->glClear(GL_COLOR_BUFFER_BIT);
}

void GLWindow::printContextInformation()
{
  QString glType;
  QString glVersion;
  QString glProfile;

  // Get Version Information
  glType = (context()->isOpenGLES()) ? "OpenGL ES" : "OpenGL";
  glVersion = reinterpret_cast<const char*>(MY_GL_FUNC->glGetString(GL_VERSION));

  // Get Profile Information
#define CASE(c) case QSurfaceFormat::c: glProfile = #c; break
  switch (format().profile())
  {
    CASE(NoProfile);
    CASE(CoreProfile);
    CASE(CompatibilityProfile);
  }
#undef CASE

  // qPrintable() will print our QString w/o quotes around it.
  qDebug() << qPrintable(glType) << qPrintable(glVersion) << "(" << qPrintable(glProfile) << ")";
}
